Repository navigation
Conversation
LoggerManager is a singleton, but __init__ returned early only when the requested level differed from the current one. Every same-level call ran _create_logger() and _configure_error_handler() again and added another file (or stdout) handler and another WebappErrorHandler to the shared "file_logger" logger. About ten modules fetch the logger at import time, and duckdb_sql, variable_explorer and set_notebook_path call it per use, so a kernel ends up with ten or more copies of each handler and the count keeps growing. Each record is then written that many times, each ERROR is reported to the webapp that many times, and every extra FileHandler holds a file descriptor. __init__ now returns whenever the manager is initialized, after updating the level if it changed. log_file is ignored after the first call.
|
📦 Python package built successfully!
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #158 +/- ##
==========================================
+ Coverage 78.57% 78.58% +0.01%
==========================================
Files 121 121
Lines 6935 6936 +1
Branches 1009 1010 +1
==========================================
+ Hits 5449 5451 +2
Misses 1179 1179
+ Partials 307 306 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
🚀 Review App Deployment Started
|
The server command's get_logger(level=level) call never set up file logging. Importing deepnote_toolkit has already created the logger and picked its log file from the config at import time, so the call only sets the level, and a log_dir from --config doesn't move the log file.
|
@coderabbitai full review |
Action performed
|
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
TestLoggerManager deleted CI from the real environment in tearDown and in individual tests, and never restored it. GitHub Actions sets CI=true and runs the unit suite in one process, so every test after this class ran with CI unset, which switches the toolkit logger from stdout to a file and adds the webapp error handler. setUp now snapshots os.environ with mock.patch.dict and restores it on cleanup, and pops CI once so the tests start outside CI. The per-test and tearDown deletions go.
|
@m1so it was just a small change, so I just reused a proper test setup from other test |
Summary
LoggerManageris a singleton, but__init__returned early only when the requested level differed from the current one. Every call at the same level ran_create_logger()and_configure_error_handler()again, adding anotherFileHandler(a stdoutStreamHandlerunder CI) and anotherWebappErrorHandlerto the sharedfile_loggerlogger.About ten modules fetch the logger at import time, and
sql/duckdb_sql.py,variable_explorer.pyandset_notebook_path.pyfetch it on each use. Onmain:import deepnote_toolkit.cli.serverLoggerManager().get_logger()calls__init__now returns whenever the manager is initialized, after updating the level if it changed.Impact on
mainhelpers.logonce per handler, so ten or more times in a kernel.WebappErrorHandler. Each post makes up to three attempts with a 5 s timeout, so while the endpoint hangs, one ERROR can block the logging thread for about 16 s per copy. This figure comes from reading the code; I didn't measure it.FileHandlerkeeps a file descriptor open for the life of the process.Behavior changes
log_fileis ignored after the first call. Before, a later call at the same level with a different path added a handler for that path, and a call at a different level ignored it. No caller passeslog_file. The__init__andget_loggerdocstrings now say so.deepnote-toolkit server --debug(or-vv) no longer re-creates handlers. Hereget_logger(level=level)atcli/server.py:73matched the import-time DEBUG level, so onmainit re-created the handlers. They went to the same path, because the memoized config isn't re-read. With the default level and--quietthe level differs, so this call already returned early. The comments atcli/server.py:61-62andcli/main.py:54-55said this call sets up file logging, so that the log directory follows the CLI config. That wasn't true onmaineither. Importingdeepnote_toolkitcreates the logger and picks its log file from the config at import time, so alog_dirset through--confignever moved it. The second commit rewrites theserver.pycomment to say the call only sets the level, and removes themain.pynote.Not changed
LoggerManager()defaults tolevel=logging.DEBUG. So a bareLoggerManager()afterget_logger(level=X)resets the level to DEBUG, before and after this change. I found this by reading the code; I didn't check whether it happens in a running server.Tests
test_repeated_get_logger_handles_each_record_once: callsget_logger()twice, logs one ERROR, and checks that the log file holds it once and thatreport_error_to_webappis called once.main'slogging.pywithAssertionError: 2 != 1.autospec=True, so a signature mismatch thatWebappErrorHandler.emitwould swallow fails the test.test_get_logger_updates_level_after_initialization: guards the level-update branch that the fix moved. It starts at WARNING, lowers to INFO and checks that an INFO line appears, then raises back to WARNING and checks that the next INFO line doesn't. It fails when either the logger's or the handlers'setLevelcall is dropped, whenself.levelisn't updated, or when the condition is narrowed to one direction.TestLoggerManagerfixture (third commit):setUpnow snapshotsos.environwithmock.patch.dict, restores it on cleanup, and popsCI. Before,tearDownand some tests deletedCIfrom the real environment. GitHub Actions setsCI=trueand runs the unit suite in one process, so every test after this class ran withCIunset. A probe test run after the class now seesCIunchanged, whether it started set or unset. Without the pop, the three file-logger tests fail underCI=true.tests/unit/test_logging_utils.py: 14 passed, both with and withoutCI=true.CI=true.maingives 1474 passed, 4 skipped, with the same 13 warnings.